﻿using System;
using System.Collections.Generic;

namespace _05迭代器模式
{
    /// <summary>
    /// 具体的迭代器
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ConcreteIterator<T> : Iterator<T>
    {
        private List<T> list = null;
        private int index = 0;
        public ConcreteIterator(List<T> myList)
        {
            this.list = myList;
        }

        public T First()
        {
            return list[0];
        }

        public bool HasNext()
        {
            if (index < list.Count - 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public T Next()
        {
            T obj = default(T);
            if (this.HasNext())
            {
                obj = list[++index];
            }
            return obj;
        }
    }
}
